<%@page import="org.apache.mahout.cf.taste.recommender.RecommendedItem"%>
<%@page import="recommendation.Recommendation"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.UserMethods"%>
<%@ page import="org.apache.mahout.cf.taste.model.DataModel" %>

<script>
$("a.friends").click(function() {
		$("#friends_content").hide().fadeIn(1000).load("friends/userProfile.jsp?user_id="+ $(this).attr('id'));
		return false;
	});
</script>


<div class="page-header">
	<h2 class="page-title">Rekomendacje znajomych</h2>
</div>

<br />

<div id="content">

<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						 Integer user_id = (Integer) session.getAttribute("user_id");
							response.setContentType("text/html");
							if (user_id != null) {
								RelationMethods rm = new RelationMethods();
								UserMethods um = new UserMethods();
								if (rm.listAllFriends(sessionFactory, s, user_id).size()==0){
									out.println("Musisz mieć conajmniej jednego znajomego zeby zobaczyc rekomendacje");
								} else {
								int items = 9;
						
					%> 
		
<% Recommendation r = new Recommendation();
RecommendationMethods recm = new RecommendationMethods();

DataModel dm = r.createFriendDataModel(sessionFactory, s);
List<RecommendedItem> recommendations = r.createFriendRecommendationsForUser(sessionFactory, s, dm, user_id, items);
if (recommendations.size()==0){
	out.println("Brak rekomendacji");
}
else {
	for (RecommendedItem recommendation : recommendations) {
		//recm.createGameRecommendation(sessionFactory, s, user_id, Integer.valueOf(String.valueOf(recommendation.getItemID())), Double.valueOf(recommendation.getValue()));
	int friend = Integer.valueOf(String.valueOf(recommendation.getItemID()));
		  System.out.println(recommendation);
		  User f = um.id_to_user(sessionFactory, s, friend);
		  %>
		  <div class="col-sm-4 col-md-4 user-details">
            <div class="user-image">
                <img src="http://www.gravatar.com/avatar/2ab7b2009d27ec37bffee791819a090c?s=100&d=mm&r=g" alt="Karan Singh Sisodia" title="Karan Singh Sisodia" class="img-circle">
            </div>
            <div class="user-info-block" >
                <div class="user-heading">
                    <h3><% out.println("<a class=\"friends\" id=\""+ f.getUser_id()+ "\" href=\"#\">" + f.getUsername() + "</a>"); %> </h3>
                    <span class="help-block">Cos tam cos tam</span>
                </div>
</div>

</div>
<%
		}
}

		}
		
			
		}
		s.getTransaction().commit();
		%>
	


</div>
